/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tao.pattern.observer;

/**
 * The UniqueObservable class is an observable subject which accept only one observer
 * 
 * @author Joe Choi
 * @version 1.0.0
 * @see UniqueObservable
 */
public class UniqueObservable<E> {
	public UniqueObservable() {
		observer = null;
	}
	
	public void register(Observer<E> observer) {
		this.observer = observer;
	}

	public Observer<E> remove() {
		Observer<E> tmp = this.observer;
		this.observer = null;
		return(tmp);
	}
	
	public void notifyObserver(E event) {
		if(observer != null) observer.notified(event);
	}

	private Observer<E> observer;
}
